/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   gbx-emu - mainwindow.h                                                *
 *   gbx-emu homepage: http://code.google.com/p/gbx-emu/                   *
 *   Copyright (C) 2009 olejl77@gmail.com                                  *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QPixmap>
#include <QSignalMapper>
#include "../core/gameboy.h"

namespace Ui
{
    class MainWindowClass;
}

class DebuggerWidget;
class Debugger;
class Log;
class Cpu;
class QSettings;
class MainWindow : public QMainWindow, public Common
{
    Q_OBJECT
private:
    Gameboy _gb;
    Debugger *_dbg;
    DebuggerWidget *_dbgWidget;
    Log *_log;
    Cpu *_cpu;
    QSettings *m_settings;

    int m_up, m_down, m_left, m_right, m_select, m_start, m_a, m_b;

    Ui::MainWindowClass *ui;
    QString fileName;

    QPixmap pixmap;
    QPoint pixmapOffset;

    QSignalMapper *smLog;
    QSignalMapper *smLevel;

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void setDebugger(Debugger *ptr) { _dbg = ptr; }
    void setCpu(Cpu *ptr) { _cpu = ptr; }
    DebuggerWidget * startDebugger();
    void setUp(int key) { m_up = key; }
    void setDown(int key) { m_down = key; }
    void setLeft(int key) { m_left = key; }
    void setRight(int key) { m_right = key; }
    void setSelect(int key) { m_select = key; }
    void setStart(int key) { m_start = key; }
    void setA(int key) { m_a = key; }
    void setB(int key) { m_b = key; }


protected:
    void paintEvent(QPaintEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void closeEvent(QCloseEvent* event);

private slots:
    void updatePixmap(const QImage &image);
    void updateFps(double fps);
    void open();
    void start();
    void stop();
    void enableDebugger();
    void enableFrameLimiter();
    void writeSettings();
    void readSettings();
    void showAbout();
    void showSettings();
};

#endif // MAINWINDOW_H
